<template>
	<div class="audit-wrapper">
		<div class="head">
			<span class="title">
				返佣审核详情
			</span>

			<div class="right-btn">
				<el-button plain @click="goBack">
					{{ $t('common.back') }}
				</el-button>
			</div>
		</div>
		<div class="audit-content detailBoxStyle flex-row-container">
			<div class="tree-box mr15">
				<CommonProxyTree
					ref="proxyTree"
					:selectedData.sync="selectedData"
					:detailData="detailData"
					:createdAtEnd="proxyCreatedAtEnd"
				/>
			</div>
			<div class="treeRight">
				<div v-if="selectedData.type === 1">
					<ProxyCommission
						:detailData="detailData"
						:proxyRebateDetail="proxyRebateDetail"
						:proxyAccountInfo="proxyAccountInfo"
						:tableCommissionDataTop="tableCommissionDataTop"
						:tableCommissionDataBottom="tableCommissionDataBottom"
						:proxyRebateAuditInfo="proxyRebateAuditInfo"
					/>
				</div>
				<div v-else class="block rebate-details pl0 pr0">
					<div class="block-content">
						<CommissionBouns
							:selectedData="selectedData"
							:row="detailData"
						/>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import list from '@/mixins/list'
import dayjs from 'dayjs'
import CommonProxyTree from '@/components/CommonProxyTree/index'
import CommissionBouns from '@/components/Funds/CommissionBouns'
import ProxyCommission from '@/components/Funds/ProxyCommission'
export default {
	components: {
		CommonProxyTree,
		CommissionBouns,
		ProxyCommission
	},
	mixins: [list],
	props: {
		detailData: {
			type: Object,
			default: () => {}
		}
	},
	data() {
		return {
			selectedData: {
				type: 1,
				userName: ''
			},
			paramProxyId: undefined,
			detailProxyName: undefined,
			// 本期返点明细
			proxyRebateDetail: [],
			// 代理信息
			proxyAccountInfo: {},
			tableCommissionDataTop: [],
			tableCommissionDataBottom: [],
			proxyRebateAuditInfo: [],
			loading: false,
			// 当前选中的代理账号
			currentProxyId2: this.detailData?.topProxyId
		}
	},
	computed: {
		proxyCreatedAtEnd() {
			return dayjs(String(this.detailData?.cycleEndDate)).format(
				'YYYY-MM-DD 23:59:59'
			)
		}
	},
	watch: {
		selectedData: {
			handler(next) {
				if (next.type === 1 && next.id) {
					this.paramProxyId = next.id
					this.getProxyAuditDetail()
				}
			},
			immediate: true
		}
	},
	mounted() {},
	methods: {
		// 获取返佣审核详情
		async getProxyAuditDetail() {
			this.proxyAccountInfo = {}
			this.proxyRebateDetail = []
			this.tableCommissionDataTop = []
			this.tableCommissionDataBottom = []
			this.proxyRebateAuditInfo = []
			this.loading = true
			const params = {
				proxyId: this.detailData?.proxyId,
				cycleStartDate: this.detailData?.cycleStartDate,
				cycleEndDate: this.detailData?.cycleEndDate
			}
			if (this.paramProxyId) {
				params.proxyId = this.paramProxyId
			}
			await this.$api
				.getProxySettlementCommissionDetail(params)
				.then((res) => {
					// 代理账号信息
					this.proxyAccountInfo = res?.data?.proxyResp || {}
					this.detailProxyName = this.proxyAccountInfo?.userName
					// 应收返佣统计
					if (res?.data?.settlementCommissionProxyRecordRspDTO) {
						this.proxyRebateDetail = [
							res?.data?.settlementCommissionProxyRecordRspDTO
						]
						// 获取审核信息
						if (this.proxyRebateDetail[0].audit1Operator) {
							this.proxyRebateAuditInfo.push({
								lockOperator: this.proxyRebateDetail[0]
									.audit1Operator,
								auditTime: this.proxyRebateDetail[0].audit1Time,
								auditDesc: this.proxyRebateDetail[0].audit1Desc
							})
						}
						if (this.proxyRebateDetail[0].audit2Operator) {
							this.proxyRebateAuditInfo.push({
								lockOperator: this.proxyRebateDetail[0]
									.audit2Operator,
								auditTime: this.proxyRebateDetail[0].audit2Time,
								auditDesc: this.proxyRebateDetail[0].audit2Desc
							})
						}
					}
					// 团队返佣明细
					// settlementCode: 1：德州-俱乐部 2：德州-保险 3：其他
					const commissionData =
						res?.data?.dwmCommissionDetailProxyDDTOS || []
					commissionData.forEach((item) => {
						if (item.settlementCode === '1') {
							this.tableCommissionDataTop.push(item)
						} else {
							this.tableCommissionDataBottom.push(item)
						}
					})
					this.loading = false
				})
				.catch(() => {
					this.loading = false
				})
		},
		// 返回审核列表
		goBack() {
			this.$emit('goBack')
		}
	}
}
</script>

<style lang="scss" scoped>
.center-footer,
.form-ddog {
	display: flex;
	align-content: center;
	justify-content: center;
}
.tree-box {
	width: 320px;
	flex-shrink: 0;
	height: auto;
	overflow: auto;
	::v-deep .el-card__body {
		padding-left: 0px;
		width: 100%;
	}
}
::v-deep .el-tabs__item {
	font-size: 16px;
	font-weight: bold;
}
.treeRight {
	width: calc(100% - 245px);
	display: flex;
	-o-display: flex;
	-ms-display: flex;
	-webkit-display: flex;
	-moz-display: flex;
	flex-direction: column;
	-o-flex-direction: column;
	-ms-flex-direction: column;
	-webkit-flex-direction: column;
	-moz-flex-direction: column;
	overflow-y: auto;
	overflow-x: hidden;
}
.txtfeed {
	width: 160px;
	table-layout: fixed;
	word-break: break-all;
	overflow: hidden;
}
.disColor {
	padding-left: 9px;
	color: rgb(75, 88, 211);
}
.contentBox {
	font-size: 16px;
	padding-block: 9px;
}
.water-dialog,
.venueFee-dialog,
.rules-dialog,
.level-dialog,
.cancel-dialog {
	::v-deep .el-dialog__header {
		text-align: left;
		color: #909399;
		font-weight: 700;
		border-bottom: 1px solid #00000015;
	}
}

.active-dialog {
	::v-deep .el-dialog__header {
		padding: 10px 20px 10px;
	}
	::v-deep .el-dialog__body {
		padding: 20px 20px;
	}
	.tabs-wrapper {
		display: flex;
		.tab {
			width: 120px;
			height: 40px;
			line-height: 40px;
			text-align: center;
			border: 1px solid rgba(0, 0, 0, 0.15);
			font-size: 14px;
			font-weight: 600;
			color: #000000a3;
			cursor: pointer;
			margin-right: 20px;
		}
	}
	.active {
		background: #00bfbf;
	}
	.type-name {
		padding: 0 0 20px;
		font-weight: 600;
		.num {
			color: blue;
		}
	}
}

.audit-wrapper {
	color: #666666;
	margin: 24px 16px 20px 16px;
	.head {
		height: 70px;
		line-height: 70px;
		width: 100%;
		background: #000;
		border-radius: 2px;
		padding: 0 30px;
		.title {
			font-weight: 600;
			color: rgb(192, 190, 190);
		}
		.right-btn {
			float: right;
		}
	}
	.audit-content {
		.block {
			padding: 30px 30px 0px 30px;
			margin-right: 15px;
			.name {
				font-weight: 600;
			}
			.block-content {
				position: relative;
				width: 100%;
				margin-top: 15px;
			}
		}
		.rebate-details {
			padding-bottom: 20px;
			.details-page {
				margin-top: 10px;
				position: absolute;
				right: 0;
			}
		}
		.review-info {
			display: flex;
			margin-top: 15px;
			flex-direction: column;
			border-left: 1px solid #e0e0e0;
			border-top: 1px solid #e0e0e0;
			.row {
				display: flex;
				.gird {
					min-height: 45px;
					font-size: 14px;
					text-align: center;
					flex: 1;
					border-right: 1px solid #e0e0e0;
					border-bottom: 1px solid #e0e0e0;
					word-break: break-all;
					display: flex;
					align-items: center;
					justify-content: center;
					padding: 2px;
				}
			}
			.title {
				background: #efefef;
			}
			.end-row {
				width: 50%;
			}
		}
	}
	.active-dialog {
		::v-deep .el-dialog__header {
			padding: 10px 20px 10px;
			border-bottom: 1px solid #00000015;
		}
		.tabs-wrapper {
			display: flex;
			.tab {
				width: 120px;
				height: 40px;
				line-height: 40px;
				text-align: center;
				border: 1px solid rgba(0, 0, 0, 0.15);
				font-size: 14px;
				font-weight: 600;
				color: #000000a3;
				cursor: pointer;
				margin-right: 20px;
				background: #e7e6e6;
			}
		}
		.active {
			background: #00bfbf !important;
		}
		.disabled {
			pointer-events: none;
		}
		.type-name {
			padding: 0 0 20px;
			font-weight: 600;
			.num {
				color: blue;
			}
		}
	}
}
::v-deep .el-table {
	.high-light {
		color: #0dc5e3;
	}
}
::v-deep .audit-dialog .el-form-item__error {
	left: 0;
}

.vi_VN,
.th_TH,
.en_US {
	.audit-time {
		font-size: 12px;
	}
}
</style>
